package com.beiming.moudle.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.beiming.moudle.auth.dao.ShopCarDao;
import com.beiming.moudle.auth.entity.BussEntity;
import com.beiming.moudle.auth.entity.ShopCarEntity;
import com.beiming.moudle.auth.entity.utillClass.ShopCarPage;
import com.beiming.moudle.auth.entity.utillClass.ShopCarUtil;
import com.beiming.moudle.auth.service.ShopCarService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ShopCarServiceImpl extends ServiceImpl<ShopCarDao, ShopCarEntity> implements ShopCarService {
    @Autowired
    private ShopCarDao shopCarDao;

    @Override
    public int updateShopCar(ShopCarEntity shopCarEntity) {
//        QueryWrapper<ShopCarEntity> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("cart_id",shopCarEntity.getCartId());
//        ShopCarEntity shopCarEntity1=  shopCarDao.selectOne(queryWrapper);
        shopCarDao.updateById(shopCarEntity);
        return 0;
    }

    @Override
    public IPage<ShopCarEntity> getMsgPage(ShopCarPage shopCarPage) {
        LambdaQueryWrapper<ShopCarEntity> lqw = new LambdaQueryWrapper<>();
        lqw.like(null!=(shopCarPage.getCustomerId()),ShopCarEntity::getCustomerId,shopCarPage.getCustomerId());
        IPage pag = new Page(shopCarPage.getCurrentPage(),shopCarPage.getPageSize());
        shopCarDao.selectPage(pag,lqw);
        return pag;
    }

    @Override
    public int addShopCar(ShopCarEntity shopCarEntity) {
//        QueryWrapper<ShopCarEntity> queryWrapper = new QueryWrapper<>();
//        queryWrapper.eq("bussiness_id",shopCarEntity.getCustomerId());
//        queryWrapper.eq("",shopCarEntity.getProductId());
//        ShopCarEntity shopCarEntity1=  shopCarDao.selectOne(queryWrapper);
//
        return shopCarDao.insert(shopCarEntity);
    }

    @Override
    public int deleteShopCar(int i) {
        shopCarDao.deleteById(i);
        return 0;
    }

    @Override
    public int deleteAnyShopCar(int i) {
        QueryWrapper<ShopCarEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("customer_id",i);
        shopCarDao.delete(queryWrapper);
        return 0;
    }
}

